/* code for Firefox, Chrome, Opera, Safari */
if(window.XMLHttpRequest) {
    xml_http = new XMLHttpRequest();
    alert('Chrome / Firefox / Opera / Safari used');
} else if(window.ActiveXObject) {
    try { 
	/* code for the later verion of IE6. */
	xml_http = new ActiveXObject("Msxml2.XMLHTTP");
	alert('The latest version of IE');
    } catch(e) {
	try { 
	    /* code for IE6, IE5 */
	    xml_http = new ActiveXObject("Microsoft.XMLHTTP");
	    alert('IE5 / IE6');
	} catch(e) {}
    }
}

/* Request XML */
xml_http.open("GET","xml/AMLogic-m3-product.xml",false);
xml_http.send();
xml_Doc = xml_http.responseXML;
alert(xml_Doc);

/* Parsing XML */
var i = 0;
var j = 0;
var comp = xml_Doc.getElementsByTagName("component");
alert(comp);
var comp_sum = comp.length;
var comp_collection = new Array(comp_sum);
var spec_sum = 0;
var spec_collection = new Array(comp_sum);
var spec_id_collection = new Array(comp_sum);
var spec_desc_collection = new Array(comp_sum);
var show_page = '';
var show_result = '';
var mail_to = '';
for(i = 0; i < comp_sum; i++) {
    comp_collection[i] = comp[i].getAttribute("name");
    spec_sum = comp[i].getElementsByTagName("component-item").length;
    spec_collection[i] = new Array(spec_sum);
    spec_id_collection[i] = new Array(spec_sum);
    spec_desc_collection[i] = new Array(spec_sum);
    for(j = 0; j < spec_sum; j++) {
//	spec_collection[i][j] = comp[i].children[j].getAttribute("name");
//	spec_id_collection[i][j] = comp[i].children[j].getAttribute("value");
//	spec_desc_collection[i][j] = comp[i].children[j].getElementsByTagName("text")[0].childNodes[0].nodeValue;
	spec_collection[i][j] = $(comp[0]).children(':eq('+j+')').attr('name');
	spec_id_collection[i][j] = $(comp[0]).children(':eq('+j+')').attr('value');
	spec_desc_collection[i][j] = $(comp[0]).children(':eq('+j+')').children('text').text();
    }
}

/* Function */
function showPage() {
    mail_to = document.getElementById("Mail");
    mail_to.value = "";
    show_page = document.getElementById("ShowPage");
    for(i = 0; i < comp_sum; i++) {
	var title = "Choose " + comp_collection[i] + " : ";
	if(i == 0) { show_page.innerHTML += title + "<br />"; }
	else { show_page.innerHTML +="<br />" + title + "<br />"; }
	for(j = 0; j < spec_collection[i].length; j++) {
	    var item = '<input type="radio" name="' + comp_collection[i] + '" value="' + spec_id_collection[i][j] + '">[' + spec_id_collection[i][j] + '] ' + spec_desc_collection[i][j] + '</input><br />';
	    show_page.innerHTML += item;
	}
    }
    cleanColumn();
}
